package com.uchengwang.ui.base_ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.ui.base_ui.bean.MoreBean;
import com.uchengwang.ui.utils.PopupUtils;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * Created by U城网 on 2017/6/24.
 * 更多操作adapter
 */

public class MoreAdapter extends RecyclerView.Adapter<MoreAdapter.MoreVH>{
    private List<MoreBean> list;
    private Context context;
    private PopupUtils.OnItemPopupClickListener listener;

    public MoreAdapter(Context context, List<MoreBean> list){
        this.context = context;
        this.list = list;
    }

    public void setListener(PopupUtils.OnItemPopupClickListener listener){
        this.listener = listener;
    }

    @Override
    public MoreVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.more_item_layout, parent, false);

        return new MoreVH(view);
    }

    @Override
    public void onBindViewHolder(MoreVH holder, final int position) {
        final MoreBean bean = list.get(position);

         holder.imageView.setImageResource(bean.getRes());
        holder.title.setText(bean.getTitle());

       holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null){
                    listener.onItemClick(position, bean.getTitle());
                }
            }
        });

    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

     class MoreVH extends RecyclerView.ViewHolder{
         private View view;
        private ImageView imageView;
        private TextView title;

         public MoreVH(View itemView) {
             super(itemView);

             view = itemView;
             AutoUtils.autoSize(itemView);

             imageView = (ImageView) itemView.findViewById(R.id.moreItem_image);
             title = (TextView) itemView.findViewById(R.id.moreItem_title);
         }
     }
}
